import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { User } from 'src/interface/user.interface';
import { AuthService } from './auth.service';

@Controller('auth')
@ApiTags('用户验证模块')
export class AuthController {
  constructor(private readonly authService: AuthService) { }

  @Post('login')
  @ApiOperation({ summary: '用户登录' })
  async userLogin(@Body() userDto: User) {
    return await this.authService.login(userDto)
  }

  @Get('captcha/:id') // 如果要删除某个验证码，就传id进来，否则就是默认生成一个
  @ApiOperation({
    summary: '获取注册验证码'
  })
  async getCaptcha(@Param('id') id: string) {
    return await this.authService.createCaptcha(id)
  }

  @Post('verify')
  @ApiOperation({
    summary: '验证注册验证码'
  })
  verify(@Body() captcha: { code: string, id: string }) {
    return this.authService.verification(captcha.code, captcha.id)
  }
}
